{extend name='base'/}
{block name='title'}修改资料{/block}
{block name='main'}
<link rel="stylesheet" href="__CSS__/booklist.css">
<style>
    .main {
        background: url("__IMG__/list_bg.jpg") left top repeat-y;
    }
    .user-form {
        width: 60%;
    }
    .user-form label{
        font-size: 14px;
    }
</style>
<div class="row m-0 mt-3 main">
    {include file='user/user_left'}
    <div class="right flex-1">
        <form class="user-form mb-3">
            <div class="form-group">
                <img style="width: 100px;height: 100px;" id="avatar-preview" src="{$user.avatar}">
            </div>
            <div class="form-group">
                <label for="avatar">头像 <span class="text-danger">*</span></label>
                <div class="" style="display: flex;">
                    <input type="text" name="data[avatar]" class="form-control" id="avatar" value="{$user.avatar}">
                    <a href="javascript:void(0)" class="btn btn-info" onclick="javascript:uploadOneImage('#avatar', '#avatar-preview')">上传图片</a>
                </div>
            </div>
            <div class="form-group">
                <label for="username">账号 <span class="text-danger">*</span></label>
                <input type="text" name="data[username]" class="form-control" id="username" value="{$user.username}">
            </div>
            <!--<div class="form-group">-->
                <!--<label for="password">密码</label>-->
                <!--<input type="password"  name="data[password]" class="form-control" id="password" value="" placeholder="不填写，则不做修改">-->
            <!--</div>-->
            <div class="form-group">
                <label for="truename">姓名 <span class="text-danger">*</span></label>
                <input type="text"  name="data[truename]" class="form-control" id="truename" value="{$user.truename}">
            </div>
            <div class="form-group">
                <label for="mobile">手机号 <span class="text-danger">*</span></label>
                <input type="text"  name="data[mobile]" class="form-control" id="mobile" value="{$user.mobile}">
            </div>
            <div class="form-group">
                <label for="email">邮箱</label>
                <input type="email" name="data[email]" class="form-control" id="email" value="{$user.email}">
            </div>
            <button type="button" class="btn btn-primary edituser-btn">立即修改</button>
        </form>
    </div>
</div>
{/block}

{block name='js'}
<script>
    let UPLOADURL = "{:url('common/upload/index')}";
</script>
<script src="__JS__/upload.js"></script>
<script>
    $(function () {
        let lock = false;
        $(".edituser-btn").on('click', function () {
           if (lock) {
               return false;
           }
           lock = true;
           $.post("{:url('User/edit')}", $(".user-form").serialize(), function (res) {
               if (res.code == 0) {
                   swal("提示", res.msg, {
                       icon : "error",
                       buttons: {
                           confirm: {
                               className : 'btn btn-danger',
                               text : '确定',
                           }
                       },
                   });
               }else{
                   swal("提示", res.msg, {
                       icon : "success",
                       buttons: {
                           confirm: {
                               className : 'btn btn-success',
                               text : '确定',
                           }
                       }
                   }).then(function () {
                       window.location.replace("{:url('User/index')}");
                   });
               }
               lock = false;
           }, 'json');
        });
    });
</script>
{/block}